#include <stdio.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
static void get_localtime_string(time_t sec, const char* format, char* str, size_t size)
{
    struct tm t;
    localtime_r(&sec, &t);

    snprintf(str, size, "%d-%02d-%02d %02d:%02d:%02d", 
            1900+t.tm_year, 1+t.tm_mon, t.tm_mday, 
            t.tm_hour, t.tm_min, t.tm_sec);
}


int main()
{
    char str[100];

    while(1) {
#if 0
        time_t sec = time(NULL);
        get_localtime_string(sec, "", str, 100);
        printf("%s    [%ld]\n", str, sec);
#endif
#if 0
        time_t sec = time(NULL);
        struct tm t;
        localtime_r(&sec, &t);
        printf("tm_hour = %d     [%d].\n", t.tm_hour, sec);
#endif
    time_t tm;  
    struct tm tm_time;  
    time(&tm);  
    memset(&tm_time, 0, sizeof(tm_time));
    localtime_r(&tm, &tm_time);
    memcpy(&tm_time, localtime(&tm), sizeof(tm_time));  
        printf("tm_hour = %d     [%d].\n", tm_time.tm_hour, tm);



        sleep(1);
    }

    return 0;
}
